package com.design.pattern.single;

/**
 * @author wangyingjie
 * @date
 * @remark 双检锁单例
 */
public class DCLSingleton {

    //volatile 保证不同线程之间对变量的可见性，即一个线程修改变量存入主内存，另一个线程获取即可看到新值
    private volatile static DCLSingleton dclSingleton;

    private DCLSingleton() {
    }

    public static DCLSingleton getInstance(){
        if (dclSingleton == null){
            synchronized (DCLSingleton.class){
                if (dclSingleton == null){
                    dclSingleton = new DCLSingleton();
                }
            }
        }
        return dclSingleton;
    }
}
